package net.lainiao.morethread.Chapter3.demo3;

import java.util.concurrent.CountDownLatch;

/**
 * Created by Administrator on 2017/3/1.
 */
public class VideoConference implements Runnable {
    private final CountDownLatch controller;

    public VideoConference(int number) {
        controller = new CountDownLatch(number);
    }

    public void arrive(String name){
        System.out.printf(" :%s has arrived \n",name);
        controller.countDown();
        System.out.println("VideoConference 还在等待 "+controller.getCount()+"个操作");
    }

    @Override
    public void run() {
        System.out.println("初始化，当前需要等待的操作数量是:"+controller.getCount());
        try {
            controller.await();
            System.out.println("所有并发操作已经完成可以进行下一步");
            System.out.println("视频会议结束");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
